package com.tbsoft.ehr.action.common;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.tbsoft.ehr.action.BaseAction;
import com.tbsoft.ehr.model.WorkDaySet;
import com.tbsoft.ehr.service.common.WorkdayService;
/**
 * @desc 假期表设置
 * @author vastdream
 *
 */
public class WorkdayAction extends BaseAction {
	private Log log = LogFactory.getLog(getClass());
	private String year;
	
	private List<WorkDaySet> wdsList =  new ArrayList<WorkDaySet>();
	
	public synchronized String getYear() {
		return year;
	}

	public synchronized void setYear(String year) {
		this.year = year;
	}

	private static final long serialVersionUID = 1L;
	
	private WorkdayService workdayService;

	public String set(){
		if(year == null || year.isEmpty()){
			year = new SimpleDateFormat("yyyy").format(new Date());
		}
		List<WorkDaySet> tmpList = workdayService.getWorkDaySetBy(year);
		wdsList.clear();
		wdsList.addAll(tmpList);
		return "set";
	}
	public String save(){
		try{
			workdayService.saveWorkDays(year, wdsList);
		}catch(Exception e){
			log.error("save exception", e);
			errorReturn("设置假期失败");
		}
		return SUCCESS;
	}
	
	public synchronized void setWorkdayService(WorkdayService workdayService) {
		this.workdayService = workdayService;
	}

	public synchronized List<WorkDaySet> getWdsList() {
		return wdsList;
	}

	public synchronized void setWdsList(List<WorkDaySet> wdsList) {
		this.wdsList = wdsList;
	}
	
	
}
